package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.dtos.OrderCarRentMoneyDto;
import com.lzy.cloud.order.request.OrderCarRentMoneyRequest;
import com.lzy.cloud.order.response.OrderCarRentMoneyResponse;
import com.lzy.cloud.order.service.OrderCarRentMoneyService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:房车租赁的价格明细
 * @author: liyun
 * @create: 2018-07-05 13:49
 */
@RestController
@RequestMapping("/order/car/rent/money")
public class OrderCarRentMoneyController {
    @Autowired
    private OrderCarRentMoneyService orderCarRentMoneyService;

    /**
     * 根据订单id查询房车租赁的价格明细
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/find/by/order/id/{orderId}",method = RequestMethod.GET)
    public Result queryListByOrderId(@PathVariable("orderId") String orderId) {
        Ensure.that(orderId).isNotNull("00010003");
        OrderCarRentMoneyDto orderCarRentMoneyDto = new OrderCarRentMoneyDto();
        orderCarRentMoneyDto.setOrderId(orderId);
        List<OrderCarRentMoneyDto> list = orderCarRentMoneyService.queryList(orderCarRentMoneyDto);
        return new Result(DozerUtils.map(list, OrderCarRentMoneyResponse.class));
    }

    /**
     * 新增房车租赁的价格明细
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public Result create(@RequestBody OrderCarRentMoneyRequest request) {
        Ensure.that(request).isNotNull("00000002");
        Long id = orderCarRentMoneyService.create(DozerUtils.map(request, OrderCarRentMoneyDto.class));
        Ensure.that(id).isGt(0, "00050001");
        return new Result(id);
    }

}
